// [SQL数据集] 接口
import { axios } from '@/utils/request';

/**
 * [SQL数据集] 获取指定SQL数据集的详细信息
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function getDatahubSqlDataset(params) {
  return axios({
    method: 'get',
    url: 'datahub/sql-dataset',
    params
  })
}

/**
 * [SQL数据集] 添加SQL数据集
 * @params data
 * {
    {"datasourceId":{"description":"数据源ID","type":"integer"}},
    {"description":{"description":"描述","type":"string"}},
    {"name":{"description":"名称","type":"string"}},
    {"parameters":{"description":"sql参数","type":"array"}},
    {"querySql":{"description":"查询sql","type":"string"}}
   }
 */
export function postDatahubSqlDataset(data) {
  return axios({
    method: 'post',
    url: 'datahub/sql-dataset',
    data
  })
}

/**
 * [SQL数据集] 编辑SQL数据集
 * @params data
 * {
    {"datasourceId":{"description":"数据源ID","type":"integer"}},
    {"description":{"description":"描述","type":"string"}},
    {"id":{"description":"主键","type":"integer"}},
    {"name":{"description":"名称","type":"string"}},
    {"parameters":{"description":"sql参数","type":"array"}},
    {"querySql":{"description":"查询sql","type":"string"}}
   }
 */
export function putDatahubSqlDataset(data) {
  return axios({
    method: 'put',
    url: 'datahub/sql-dataset',
    data
  })
}

/**
 * [SQL数据集] 删除SQL数据集
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function deleteDatahubSqlDataset(params) {
  return axios({
    method: 'delete',
    url: 'datahub/sql-dataset',
    params
  })
}

/**
 * [SQL数据集] 编辑SQL数据集字段
 * @params data
 * {
    {"aliasColumnName":{"description":"别名","type":"string"}},
    {"datesetId":{"description":"数据集ID","type":"integer"}},
    {"description":{"description":"描述","type":"string"}},
    {"originColumnName":{"description":"原始字段名","type":"string"}}
   }
 */
export function putDatahubSqlDatasetColumn(data) {
  return axios({
    method: 'put',
    url: 'datahub/sql-dataset/column',
    data
  })
}

/**
 * [SQL数据集] 获取指定SQL数据集的字段信息
 * @params params
 * {
    {"id":{"required":true,"type":"integer"}}
   }
 */
export function getDatahubSqlDatasetColumns(params) {
  return axios({
    method: 'get',
    url: 'datahub/sql-dataset/columns',
    params
  })
}

/**
 * [SQL数据集] 分页查询SQL数据集
 * @params params
 * {
    {"datasourceId":{"required":false,"type":"integer"}},
    {"name":{"required":false,"type":"string"}},
    {"pageNo":{"required":false,"type":"integer"}},
    {"pageSize":{"required":false,"type":"integer"}}
   }
 */
export function getDatahubSqlDatasetPage(params) {
  return axios({
    method: 'get',
    url: 'datahub/sql-dataset/page',
    params
  })
}

/**
 * [SQL数据集] 分页查询SQL数据集的数据
 * @params data
 * {
    {"id":{"description":"SQL数据集ID","type":"integer"}},
    {"pageNo":{"description":"分页页码, 1开始","type":"integer"}},
    {"pageSize":{"description":"每页显示数","type":"integer"}},
    {"parameters":{"description":"参数","type":"array"}},
    {"sortField":{"description":"排序字段","type":"string"}},
    {"sortOrder":{"description":"排序规则, ascend: 升序, desend: 降序","type":"string"}}
   }
 */
export function postDatahubSqlDatasetRecord(data) {
  return axios({
    method: 'post',
    url: 'datahub/sql-dataset/record',
    data
  })
}

/**
 * [SQL数据集] 主动校验
 * @params params
 * {
    {"id":{"required":false,"type":"integer"}},
    {"field":{"required":false,"type":"string"}},
    {"value":{"required":false,"type":"object"}}
   }
 */
export function getDatahubSqlDatasetVerification(params) {
  return axios({
    method: 'get',
    url: 'datahub/sql-dataset/verification',
    headers: { validate: true },
    params
  })
}

/**
 * [SQL数据集] 使用SQL分页查询数据
 * @params data
 * {
    {"datasourceId":{"description":"数据源ID","type":"integer"}},
    {"pageNo":{"description":"分页页码, 1开始","type":"integer"}},
    {"pageSize":{"description":"每页显示数","type":"integer"}},
    {"parameters":{"description":"参数","type":"array"}},
    {"querySql":{"description":"查询sql","type":"string"}},
    {"sortField":{"description":"排序字段","type":"string"}},
    {"sortOrder":{"description":"排序规则, ascend: 升序, desend: 降序","type":"string"}}
   }
 */
export function postDatahubSqlRecord(data, hideNotification = false) {
  return axios({
    method: 'post',
    url: 'datahub/sql/record',
    data,
    headers: { hideNotification },
  })
}